package com.vpen.server.controller;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONUtil;
import com.vpen.common.Matter;
import com.vpen.common.Picture;
import com.vpen.server.endpoint.MatterServerEndpoint;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述
 *
 * @author 韦鹏
 * @date 2022/11/25 14:30
 */
@Slf4j
@RestController
@RequestMapping("matter")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class MatterController {

    private final MatterServerEndpoint matterServerEndpoint;


    @GetMapping("insert/{key}")
    public String insert(@PathVariable String key) {
        Matter matter = new Matter();
        List<Picture> list = new ArrayList<>();
        list.add(new Picture().setUrl("baidu.com").setHigh(RandomUtil.randomInt(100, 200)).setWidth(RandomUtil.randomInt(100, 200)));
        list.add(new Picture().setUrl("aliyun.com").setHigh(RandomUtil.randomInt(100, 200)).setWidth(RandomUtil.randomInt(100, 200)));
        matter.setId(RandomUtil.randomLong(100, 200)).setName(RandomUtil.randomString(10)).setPictures(list);
        matterServerEndpoint.sendToUser(key, JSONUtil.toJsonStr(matter));
        return "ok";
    }


}
